<template>

  <div class="add">
    <h3 class="cll_h3">餐类管理</h3>
    <el-button type="primary" @click="newAdd" color="#999">新增</el-button>
  </div>
  <div>
    <hr />
    <div class="search">
      <el-form :model="form" label-width="120px" :inline="true" style="max-width: 460px">
        <el-form-item>
          <el-input v-model="form.input" placeholder="输入分类搜索" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handlesearch" color="#999">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <hr />
  </div>
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column  label="排序" width="180" >
        <template #default="scope">
        <p>{{tableData.indexOf(scope.row)+1}}</p>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="餐品名称" width="180" />
      <el-table-column prop="category" label="分类" />
      <el-table-column prop="price" label="金额" />
      <el-table-column prop="times" label="包含次数" />
      <el-table-column prop="status" label="启用状态" />
      <el-table-column label="操作" inline="true">
       <template #default="scope">
        <el-link type="info" class="link" @click="edit(scope.row)">编辑</el-link>
        <el-link type="info">删除</el-link>
       </template>
      </el-table-column>
    </el-table>
      <!-- 分页器 -->
      <el-pagination 
        background layout="prev, pager, next" 
        :total="total"
        :default-page-size="pageSize"
        @current-change="pagechange"
        class="paging" />
</template>

<script  lang="ts"> 
import { manage } from '@/api/manage'
import { defineComponent } from 'vue'
export default defineComponent({
  name: '',
  data() {
    return {
      form: {
        input: '',
        page:1,
      },
     
      tableData: [
        // {
  
        //   name: '月餐(20日)',
        //   category: '分类',
        //   price: 350,
        //   times: 20,
        //   status: '是',

        // },
    
      ],
      pageSize:5,
      total:5,

    }
  },
  methods: {
    edit(item:any){
      this.$router.push({
        path:'/manage/combo',
        query:item
      })
    },
    async handlesearch(){
      const data = this.form
      data.page=1

      const res = await manage(data)
       // @ts-ignore
       this.tableData=res.list
        // @ts-ignore
        this.total = res.total
        // @ts-ignore
        this.pageSize = res.pageSize
    },
    handleSelectionChange() {
      console.log(12)
    },
    newAdd() {
      this.$router.push('/manage/combo')
    },
    async pagechange(page:any){
      const data = this.form
      data.page=page
      const res = await manage(data)
      console.log(res)
        // @ts-ignore
        this.tableData=res.list
        // @ts-ignore
        this.total = res.total
        // @ts-ignore
        this.pageSize = res.pageSize
    },
  },
  created () {
    this.pagechange(1)
  },
})
</script>

<style scoped lang="less">
.link {
  margin: 0 5px;
}

.add {
  display: flex;
  justify-content: space-between;
}

.search {
  margin-top: 25px;
}
:deep(.el-button){
  color: #fff;
  border-radius:0%;
  height: 30px;
  width: 70px;

}
:deep(.el-input){
  width: 300px;
  height: 25px;
}
.paging{
  margin-top:10px ;
  margin-left: 450px;
}
</style>
